package com.example.myapp.Listviewloading;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapp.R;
import com.sak.ultilviewlib.adapter.BaseHeaderAdapter;

public class MyHeaderAdapter extends BaseHeaderAdapter {

    private ImageView loading;

    private float pull_distance=0;
    private TextView msg;

    public MyHeaderAdapter(Context context) {
        super(context);
    }

    @Override
    public View getHeaderView() {
        View mView = mInflater.inflate(R.layout.header_refresh_layout, null, false);
        loading = (ImageView) mView.findViewById(R.id.loading);
        msg= (TextView) mView.findViewById(R.id.msg);
        return mView;
    }
    /**下拉*/
    @Override
    public void pullViewToRefresh(int deltaY) {
        //这里乘以0.3 是因为UltimateRefreshView 源码中对于滑动有0.3的阻尼系数，为了保持一致
        pull_distance=pull_distance+deltaY*0.3f;
        msg.setText("下拉刷新");
        loading.setImageResource(R.drawable.down);

    }
/**拉到底*/
    @Override
    public void releaseViewToRefresh(int deltaY) {
        msg.setText("释放立即刷新");
        loading.setImageResource(R.drawable.up);
    }
    /**松手*/
    @Override
    public void headerRefreshing() {
        msg.setText("正在刷新");
        loading.setImageResource(R.drawable.qq_loading);
        AnimationDrawable mAnimationDrawable= (AnimationDrawable) loading.getDrawable();
        mAnimationDrawable.start();
    }

/**刷新完成后关闭*/
    @Override
    public void headerRefreshComplete() {
        loading.setImageResource(R.drawable.gpv);
        pull_distance=0;
    }
}
